package com.td.framework.kqxt.jqgl.action;

import java.util.Date;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.td.framework.common.AbstractAction;
import com.td.framework.kqxt.domain.KqBcsz;
import com.td.framework.kqxt.domain.KqGjgl;
import com.td.framework.kqxt.domain.KqGjgl;
import com.td.framework.webmanager.page.PageService;

/**
 * 公假管理
 * @author Administrator
 */
public class GjglAction extends AbstractAction {
	private KqGjgl kqGjgl;
	private  List<KqGjgl> gjglList;
	//=======查询条件=====
	private Date startDate;//开始时间
	private Date endDate;//结束时间
	
	private Log log = LogFactory.getLog(GjglAction.class.getName());
    
    //=======================================================公假管理START======================================
    
    /**
     * 公假列表集合
     * @return
     */
    public String listGjgl(){
    	String hql ="from KqGjgl t";    	
    	int rows = this.getBaseService().getRowsByListHql(hql);				
		page = PageService.getPage(rows, currentPage, pageSize, pageMethod);
		this.setCurrentPage(page.getCurentPage());		
		this.setPageSize(page.getPageSize());
		gjglList =this.getBaseService().getPageList(hql,page.getStartRow(),pageSize);
		return "listGjgl";
    }
    
    /**
     * 打开公假添加页面
     */
    public String createGjglForm(){
    	this.setEditState(1);
    	return "createGjgl";
    }
    
    /**
     * 添加公假信息
     * @return
     */
    public String createGjgl(){
	   boolean flag = false;
		try {
			kqGjgl.setCjr(getUserInfo().getYhm());
			kqGjgl.setCjsj(new Date());
			flag = this.getBaseService().saveEntity(kqGjgl);
		} catch (Exception e) {
			 log.error("增加公假信息失败："+e.getMessage());
			 this.handleMessage("info", "添加失败,联系管理员!");
		}
		if(flag = true){
	    	 this.handleMessage("info", "添加成功，请继续操作!");
	     }
		this.setEditState(1);
	     return "createGjgl";
    }
    
    /**
     *打开修改页面 
     * @return
     */
    public String reworkGjglForm(){
    	this.setEditState(2);
    	kqGjgl = (KqGjgl) this.getBaseService().getEntityById(KqGjgl.class,zids[0]);
    	return "reworkGjgl";
    }
    
    /**
     * 修改代码表信息
     * @return
     */
    public String reworkGjgl(){
    	this.setEditState(2);
    	 boolean flag = false;
 		try {
 			kqGjgl.setXgr(getUserInfo().getYhm());
			kqGjgl.setXgsj(new Date());
 			flag = this.getBaseService().saveOrUpdate(kqGjgl);
 		} catch (Exception e) {
 			log.error("修改公假设置失败："+e.getMessage());
 			 this.handleMessage("info", "修改失败,请联系管理员!");
 		}
 	     if(flag = true){
 	    	 this.handleMessage("info", "修改成功!");
 	     }
 	     return "reworkGjgl"; 
    }
    
    /**
     * 删除选中公假的信息
     * @return
     */
    public String removeGjgl(){
    	 boolean flag = false;
  	     flag = this.getBaseService().deleteBatch(KqGjgl.class, zids);
  	     return "listGjgl"; 
    }
    
    /**
     *打开公假设置展现页面
     * @return
     */
    public String showGjgl(){
    	this.setEditState(2);
    	kqGjgl = (KqGjgl) this.getBaseService().getEntityById(KqGjgl.class,zids[0]);
    	return "showGjgl";
    }
	public KqGjgl getKqGjgl() {
		return kqGjgl;
	}

	public void setKqGjgl(KqGjgl kqGjgl) {
		this.kqGjgl = kqGjgl;
	}

	public List<KqGjgl> getGjglList() {
		return gjglList;
	}

	public void setGjglList(List<KqGjgl> gjglList) {
		this.gjglList = gjglList;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}     
	
}
